﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace FileTransferClient
{
    public enum ProxyUse
    {
        NoUse,
        IE,
        UseProxy
    }
    public class ProxySetting
    {
        public string ProxyType
        {
            get;
            set;
        }
        public string Server
        {
            get;
            set;
        }
        public string Domain
        {
            get;
            set;
        }
        public int Port
        {
            get;
            set;
        }
        public string User
        {
            get;
            set;
        }
        public string Password
        {
            get;
            set;
        }
    }
    public class Config
    {
        public static Fcdbas.Core.Net.ProxyInfo CreateProxy(Config config)
        {
            if (config == null)
                return null;
            Fcdbas.Core.Net.ProxyInfo _ProxyInfo = null;
            if (config.ProxyUse == ProxyUse.UseProxy)
            {
                _ProxyInfo = new Fcdbas.Core.Net.ProxyInfo((Fcdbas.Core.Net.ProxyType)Enum.Parse(typeof(Fcdbas.Core.Net.ProxyType), "pt" + config.UserProxy.ProxyType),
                                new IPEndPoint(IPAddress.Parse(config.UserProxy.Server), config.UserProxy.Port),
                                new NetworkCredential(config.UserProxy.User, config.UserProxy.Password,config.UserProxy.Domain));

            }
            if (config.ProxyUse == ProxyUse.IE)
            {
                FileTransferProtocol.IEProxyInfo info = FileTransferProtocol.IEProxyInfo.GetIEProxyInfo();
                if (info.Enabled && !string.IsNullOrEmpty(info.Server))
                {
                    string[] ips = info.Server.Split(':');
                    if (ips.Length > 1)
                    {
                        _ProxyInfo = new Fcdbas.Core.Net.ProxyInfo(Fcdbas.Core.Net.ProxyType.ptHTTP,
                               new IPEndPoint(IPAddress.Parse(ips[0]), Convert.ToInt32(ips[1])),
                               null);
                   }
                }
            }
            return _ProxyInfo;
        }
        public Config()
        {
            this.UserProxy = new ProxySetting();
        }
        public string IP
        {
            get;
            set;
        }
        public int Port
        {
            get;
            set;
        }
        public string DownLoadPath
        {
            get;
            set;
        }
        public ProxyUse ProxyUse
        {
            get;
            set;
        }
        public ProxySetting UserProxy
        {
            get;
            set;
        }
    }
}
